<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <link rel="stylesheet" href="/js/lay-module/frmSelect/formSelects-v4.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>管理员信息（初始密码：123456）</legend>
    </fieldset>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">登录名称</label>
        <div class="layui-input-block">
            <input type="text" name="loginname" id="loginname" lay-verify="required" lay-reqtext="登录名称不能为空" placeholder="登录名称" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">用户名</label>
        <div class="layui-input-block">
            <input type="text" name="username" id="username" lay-verify="required" lay-reqtext="用户名不能为空" placeholder="用户名" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">角色</label>
        <div class="layui-input-block">
            <select type="text" id="roles" name='roles' placeholder="角色" autocomplete="off" class="layui-input" xm-select="select">
            </select>
        </div>
    </div>
    <div class="layui-form-item" >
        <label class="layui-form-label">部门</label>
        <div class="layui-input-block">
            <input type="text" id="deptId" name='deptId' placeholder="部门" autocomplete="off" class="layui-input" lay-filter="deptId" />
        </div>
    </div>
    <div class="layui-form-item" pane="">
        <label class="layui-form-label">性别</label>
        <div class="layui-input-block">
            <input type="radio" name="sex" value="true" title="男"" checked="">
            <input type="radio" name="sex" value="false" title="女">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">地址</label>
        <div class="layui-input-block">
            <input type="text" name="address" id="address" lay-verify="required" lay-reqtext="地址不能为空" placeholder="地址" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">手机</label>
        <div class="layui-input-block">
            <input type="text" name="phone" id="phone" lay-verify="required|phone" lay-reqtext="手机不能为空" placeholder="手机" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">邮箱</label>
        <div class="layui-input-block">
            <input type="text" name="email" id="email" lay-verify="required|email" lay-reqtext="邮箱不能为空" placeholder="邮箱" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item" pane="">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block">
            <input type="radio" name="status" value="true" title="正常" checked="">
            <input type="radio" name="status" value="false" title="禁用">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-radius layui-btn-primary" lay-submit lay-filter="saveBtn" id="saveBtn">确认保存</button>
            <button class="layui-btn layui-btn-radius layui-btn-primary"  id="backBtn">返回</button>
        </div>
    </div>
</div>
<script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="/js/lay-config.js" charset="utf-8"></script>
<script src="../../js/custorm/init.js"></script>
<script>
    layui.use(['form','formSelects'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$,formSelects = layui.formSelects;
            HavePermission('adminlist-add')==true?$("#saveBtn").show():$("#saveBtn").hide();

        var user={id:0,username:"",loginname:"",address:"",status:true,deptId:0,sex:1,roles:[],phone:"",email:""};
        form.on('submit(saveBtn)', function (data) {
            user=data.field;
            user.deptId=parseInt(data.field.deptId);
            user.sex=data.field.sex=="true"?true:false;
            user.status=data.field.status=="true"?true:false;
            AxajPost('../../api/sys/AddUser',data.field,'保存成功','../../login.html');
        });
        AxajGet('../../api/sys/GetAllRole','../../login.html',initrole);
        function initrole(data){
            var arr=new Array();
            for (var i = 0; i < data.length; i++) {                              
                var map = { "name": data[i].name, "value": (data[i].id)};
                arr.push(map);
                }
                formSelects.data('select', 'local', {
                    arr: arr
                });
            }
        $("#backBtn").click(function () {
            window.location.href="../user.html";
        });
    });
</script>
</body>
</html>